/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wat.ziszcommon.clientgui;

import java.util.List;
import javax.swing.ImageIcon;
import wat.ziszcommon.invoker.MethodException;
import wat.ziszcommon.invoker.MethodInvoker;
import wat.ziszcommon.invoker.UnauthorizedAccesException;


/**
 *
 * @author kubaolszewski
 */
public abstract class MyJPanel extends javax.swing.JPanel{
    
    protected String name;
    protected MyJTree tree;
    protected boolean isBold;
    protected ImageIcon leafIcon;
    protected MyJTabbedPane myJTabbedPane;
    private MethodInvoker methodInvoker;
            
    public MyJPanel(String name, MyJTree tree){
        this.name=name;
        this.tree=tree;
        this.isBold=false;
    }
     //kamil - wywolywana zaraz za konstruktorem
    public abstract void initClient();

    // kamil
    public final void setInvoker(MethodInvoker methodInvoker) {
        this.methodInvoker = methodInvoker;
    }
/*
    //kamil
    protected String invokeMethod(String methodName, String parameters) throws UnauthorizedAccesException, MethodException {
        return methodInvoker.invokeMethod(methodName, parameters, this.getClass().getName());
    }

    //kamil
    protected List invokeMethod(String methodName, List parameters) throws UnauthorizedAccesException, MethodException {
        return methodInvoker.invokeMethod(methodName, parameters, this.getClass().getName());
    }*/

    
    @Override
    public String toString(){
        return this.name;
    }
    
    public boolean isBold(){
        return this.isBold;
    }
    public void setBold(Boolean isBold){
        this.isBold=isBold;
        tree.repaintTree();
    }
    
    public void setImageIconByPath(String path){
        if(path==null){
            this.leafIcon=null;
            tree.repaintTree(); 
        }else{
            this.leafIcon= createImageIcon(path);
            tree.repaintTree();  
        }
    }
    public ImageIcon getImageIcon(){
        return this.leafIcon;
    }
    
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = MyJPanel.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
    public void mouseClicked(java.awt.event.MouseEvent evt){
        
    };
    
    public final void setMyJTabbedPane(MyJTabbedPane myJTabbedPane){
        this.myJTabbedPane=myJTabbedPane;
    }
    public final void closeMe(){
        this.onCloseMe();
        this.myJTabbedPane.removeMyTab(MyJPanel.this);
    }
    public void onCloseMe(){
        
    }
}
